/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using Peter.Common.MainMenu;

namespace Peter.Common.Code
{
   /// <summary>
   /// A base object for an item in the code explorer.
   /// </summary>
   public class BaseCodeItem : ViewModelBase
   {
      private object m_Tag;
      private string m_Text;
      private string m_Tooltip;
      private bool m_IsSelected;
      private bool m_IsEnabled = true;
      private MainMenuIcon m_Icon = MainMenuIcon.None;

      /// <summary>
      /// Initializes a new code item.
      /// </summary>
      /// <param name="type">Type of code item.</param>
      /// <param name="position">The position of this item in the document.</param>
      public BaseCodeItem (ObjectType type, int position)
      {
         this.ObjectType = type;
         this.Position = position;
         this.Icon = SetIconForType (type);
      }

      /// <summary>
      /// Gets the position in the document of this code item.
      /// </summary>
      public int Position { get; private set; }

      /// <summary>
      /// Gets the code item's object type.
      /// </summary>
      public ObjectType ObjectType { get; private set; }

      /// <summary>
      /// Gets or Sets the text to display.
      /// </summary>
      public string Text
      {
         get { return this.m_Text; }
         set
         {
            this.m_Text = value;
            this.OnPropertyChanged ("Text");
         }
      }

      /// <summary>
      /// Gets or Sets the tool tip to display.
      /// </summary>
      public string Tooltip
      {
         get { return this.m_Tooltip; }
         set
         {
            this.m_Tooltip = value;
            this.OnPropertyChanged ("Tooltip");
         }
      }

      /// <summary>
      /// Gets or Sets additional data attached to the node.
      /// </summary>
      public object Tag
      {
         get { return this.m_Tag; }
         set
         {
            this.m_Tag = value;
            this.OnPropertyChanged ("Data");
         }
      }

      /// <summary>
      /// Gets or Sets if this item is selected or not.
      /// </summary>
      public bool IsSelected
      {
         get { return this.m_IsSelected; }
         set
         {
            if (value != this.m_IsSelected)
            {
               this.m_IsSelected = value;
               this.OnPropertyChanged ("IsSelected");
            }
         }
      }

      /// <summary>
      /// Gets or Sets if this item is enabled.
      /// </summary>
      public bool IsEnabled
      {
         get { return this.m_IsEnabled; }
         set
         {
            if (value != this.m_IsEnabled)
            {
               this.m_IsEnabled = value;
               this.OnPropertyChanged ("IsEnabled");
            }
         }
      }

      /// <summary>
      /// Main menu icon for this item.
      /// </summary>
      public MainMenuIcon Icon
      {
         get { return this.m_Icon; }
         set
         {
            this.m_Icon = value;
            this.OnPropertyChanged ("Icon");
         }
      }

      /// <summary>
      /// Sets the icon for the current type.
      /// </summary>
      protected static MainMenuIcon SetIconForType (ObjectType type)
      {
         var icon = MainMenuIcon.QuestionSign;
         switch (type)
         {
            case ObjectType.Using:
            case ObjectType.Source:
            case ObjectType.Require:
            case ObjectType.Include:
               icon = MainMenuIcon.Domainaddon;
               break;
            case ObjectType.Field:
               icon = MainMenuIcon.Intersection;
               break;
            case ObjectType.Global:
               icon = MainMenuIcon.Domain;
               break;
            case ObjectType.Method:
               icon = MainMenuIcon.Openshare;
               break;
            case ObjectType.Function:
               icon = MainMenuIcon.Octoloaderfull;
               break;
            case ObjectType.Property:
               icon = MainMenuIcon.Calendarthree;
               break;
            case ObjectType.Event:
               icon = MainMenuIcon.Lightning;
               break;
            case ObjectType.Class:
               icon = MainMenuIcon.Garage;
               break;
            case ObjectType.Constructor:
               icon = MainMenuIcon.Enteralt;
               break;
            case ObjectType.Enumeration:
               icon = MainMenuIcon.Menu;
               break;
            case ObjectType.Namespace:
               icon = MainMenuIcon.Braces;
               break;
            case ObjectType.Local:
            case ObjectType.Variable:
               icon = MainMenuIcon.Synckeeplocal;
               break;
         }
         return icon;
      }
   }
}
